// 文本截断(限制字数140)，显示和收起文本

// 封装函数,可以再次使用
function collapsefn() {
  let container = document.getElementsByClassName("container");
  let text = document.getElementsByClassName("container-text");
  for (let i = 0; i < text.length; i++) {
    let collapse = container[i].querySelector(".collapse");
    if (text[i].innerHTML.length <= 140) {
      collapse.style.visibility = "hidden";
    } else {
      collapse.style.visibility = "visible";
      let textAll = text[i].innerHTML;
      collapse.innerHTML = "...展开";
      text[i].innerHTML = text[i].innerHTML.substr(0, 140);

      collapse.onclick = function () {
        collapse.classList.toggle("more");
        if (collapse.classList.contains("more")) {
          collapse.innerHTML = "...展开";
          text[i].innerHTML = text[i].innerHTML.substr(0, 140);
        } else {
          collapse.innerHTML = "收起";
          text[i].innerHTML = textAll.substr(0, 9999);
        }
      };
    }
  }
}
collapsefn();
// 评论的显示更多
